package com.geovis.emergency.spd.entity.system.pojo.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.geovis.emergency.spd.entity.system.entity.SystemRegion;
import com.geovis.emergency.spd.entity.system.pojo.node.INode;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 行政区划表视图实体类
 * </p>
 *
 * @author Lonsho
 * @version 1.0
 * @date 2022/6/15
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "SystemRegionVO", description = "行政区划表")
public class SystemRegionVO extends SystemRegion implements INode<SystemRegionVO> {
    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    /**
     * 父节点ID
     */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long parentId;

    /**
     * 父节点名称
     */
    private String parentName;

    /**
     * 是否有子孙节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Boolean hasChildren;

    /**
     * 子孙节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<SystemRegionVO> children;

    @Override
    public String getId() {
        return this.getCode();
    }

    @Override
    public String getParentId() {
        return this.getParentCode();
    }

    @Override
    public List<SystemRegionVO> getChildren() {
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        return this.children;
    }
}
